package com.nsxy.manager.common.interceptors;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import com.nsxy.manager.common.utils.Constants;

/**
 * @author 潜行的青衣
 * @see
 */
public class CommonInterceptor extends HandlerInterceptorAdapter {

	@Value("${context.resource.path}")
	private String resource;
	
	/* (non-Javadoc)
	 * @see org.springframework.web.servlet.HandlerInterceptor#preHandle(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse, java.lang.Object)
	 */
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		request.setAttribute(Constants.CONTEXT_PATH, request.getContextPath());
		request.setAttribute(Constants.RESOURCES_PATH, 
				new StringBuilder()
					.append(request.getContextPath())
					.append(this.resource)
					.toString());
		return true;
	}

}
